home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / Tools Plus 2.5.1 ƒ / Tools Plus 2.5.1 / Demos / Demo in C / PascalStrHandles.c
Encoding:
Text File  |  1994-05-07  |  2.2 KB  |  53 lines  |  [TEXT/KAHL]

  1. /*     "C / Pascal String Handles" supplemental file
  2.  *    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3.  *
  4.  *    re: Editing Fields
  5.  *
  6.  *    Each Tools Plus editing field uses a “string handle” (ie: a handle to a Pascal
  7.  *    string) to store the text that is displayed in the field.  The following
  8.  *    routines have been provided to facilitate moving C strings into Pascal Handle
  9.  *    structures, and vice versa.
  10.  *
  11.  *    NOTE: These routines to not check to determine if the destination variable
  12.  *                is large enough to accommodate the text being copied there.  You may
  13.  *                want to modify these routines to do such validation.
  14.  */
  15.  
  16.  
  17.  
  18. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  19.  *    Copy a C string into a Pascal “string handle”
  20.  */
  21. void Cstr2PHdl(char CSource[], Handle PDest);    // (Prototype)
  22. void Cstr2PHdl(char CSource[],                                /*Source C string                                        */
  23.                              Handle PDest)                                    /*Handle to destination Pascal            */
  24.                                                                                             /*    string.                                                    */
  25.     {
  26.     short            length;                                                        /*Source string's length                        */
  27.  
  28.  
  29.     length = strlen(CSource);                                        /*Determine length of source string    */
  30.     (**PDest) = length;                                                    /*Copy length-byte into 1st position*/
  31.     BlockMove(CSource, (*PDest) + 1, length);        /*Copy source C string (omitting        */
  32.                                                                                             /*    null terminator) to the Pascal    */
  33.                                                                                             /*    string right after the length-    */
  34.     }                                                                                        /*    byte.                                                        */
  35.  
  36.  
  37.  
  38.  
  39. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  40.  *    Copy the contents of a Pascal “string handle” into a C string
  41.  */
  42. void PHdl2Cstr(Handle PSource, char CDest[]);    //    (Prototype)
  43. void PHdl2Cstr(Handle PSource,                                /*Handle to source Pascal string        */
  44.                              char CDest[])                                    /*Destination C string                            */
  45.     {
  46.     short            length;                                                        /*Source string's length                        */
  47.  
  48.     length = (**PSource);                                                /*Determine length of source string    */
  49.     BlockMove((*PSource) + 1, CDest, length);        /*Copy source Pascal string                    */
  50.                                                                                             /*    (omitting the length byte) to        */
  51.                                                                                             /*    the C string.                                        */
  52.     CDest[length + 1] = '\0';                                        /*Null-terminate the C string                */
  53.     }                                                                                        /*                                                                    */